import $http from '@/api'
import * as types from '../mutation-types'

// initial state
const state = {
  all: []
}

// getters
const getters = {
  cate: state => {
    return state.all
  }
}

// actions
const actions = {
  getCate ({ commit }) {
    return $http.getCate()
      .then(res => {
        commit(types.RECEIVE_CATE, { res })
        return res
      })
      .catch(err => {
        console.log(err)
      })
  }
}

// mutations
const mutations = {
  [types.RECEIVE_CATE] (state, { res }) {
    state.all = res
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
